package com.changgou.seckill.service.impl;

import com.changgou.seckill.pojo.SeckillGoods;
import com.changgou.seckill.service.SeckillGoodsServcie;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author tu zy
 * @version 1.0
 * @date 2021/7/13 22:09
 */

@Service
public class SeckillGoodsServiceImpl implements SeckillGoodsServcie {

    @Autowired
    private RedisTemplate redisTemplate;


    /**
     * 根据时间和ID查询商品
     * @param time
     * @param id
     * @return
     */
    @Override
    public SeckillGoods one(String time, Long id) {
        return (SeckillGoods) redisTemplate.boundHashOps("SeckillGoods" + time).get(id);
    }

    @Override
    public List<SeckillGoods> list(String time) {

        return redisTemplate.boundHashOps("SeckillGoods" + time).values();
    }


}
